/**
' This is a part of the Primavera Portfiolio Management API examples.
' Copyright 1998, 2020, Oracle and/or its affiliates. All Rights Reserved.
'
' This source code is only intended as a supplement to the
'   Primavera Portfolio Management Enterprise API
' electronic documentation provided with the product.
'
' This source code is compatible with Primavera Portfolio Management 20.0 
**/

//*************************************************
// Set the 'Domains' value list to show only Items(1; 1.7), Portfolios, Gizmos(3;) , Wizards (; 3.14) , SubItems(;23.1023456789) and categories(;0).  Gizmos(3) will replace Applications(3)
//*************************************************

using System;
using System.Windows.Forms;

namespace ProSightWSExamples
{
        public class CpsPortfoliosValueList_UpdateValues_Example_2
        {
                private System.Net.CookieContainer mCookies = null;

                // Login needs to be called only once per session
                public void Login(string actualServerName) 
                {
                        try 
                        {
                                // mCookies is of type System.Net.CookieContainer
                                if (mCookies == null) 
                                        mCookies = new System.Net.CookieContainer();

                                // psPortfoliosSecurityRef is obtained by adding a web reference to
                                // http://refservername/ProSightWS/psPortfoliosSecurity.asmx?wsdl
                                psPortfoliosSecurityRef.psPortfoliosSecurity psSecurity = 
                                        new psPortfoliosSecurityRef.psPortfoliosSecurity();
                                        
                                psSecurity.Url = "http://" + actualServerName + "//ProSightWS/psPortfoliosSecurity.asmx?wsdl";
                                
                                psSecurity.CookieContainer = mCookies;
                                psSecurity.Login("admin", "Password", 10000); // Never code the password in the source file
                        }
                        catch (System.Web.Services.Protocols.SoapException E) 
                        {
                                // in case of exception, print the error info
                                MessageBox.Show("Error: " + 
                                        E.Detail.InnerText +  // This is the integer code of the error
                                        " " + E.Message, 
                                        "Login");
                                // in a real system, the Message is only displayed to support personnel, 
                                // not to the user
                        }
                        catch (System.Exception E) 
                        {
                                MessageBox.Show("Unexcpected Error: \n" + 
                                        E.ToString(), 
                                        "Login");
                        }           
                }               

                public void psPortfoliosValueList_UpdateValues_Example_2(string actualServerName) 
                {
                        try 
                        {
                                // psPortfoliosValueListRef is obtained by adding a web reference to
                                // http://servername/ProSightWS/psPortfoliosValueList.asmx?wsdl 
                                psPortfoliosValueListRef.psPortfoliosValueList ValueListObj =
                                        new psPortfoliosValueListRef.psPortfoliosValueList();
                                
                                ValueListObj.Url = "http://" + actualServerName + "//ProSightWS/psPortfoliosValueList.asmx?wsdl";
                                
                                // Associate ValueListObj with the session so that it inherits the login credentials
                                ValueListObj.CookieContainer = mCookies;



                                #region Prepare vaValues 

                                psPortfoliosValueListRef.psPortfoliosValueListValueInfo[] vaValues =
                                        new psPortfoliosValueListRef.psPortfoliosValueListValueInfo[6];
                                        
                                vaValues[0] = new psPortfoliosValueListRef.psPortfoliosValueListValueInfo();               
                                vaValues[0].ID=1;
                                vaValues[0].Text=@"Items";
                                vaValues[0].Weight=1.7F;      
                                vaValues[1] = new psPortfoliosValueListRef.psPortfoliosValueListValueInfo();               
                                vaValues[1].Text=@"Portfolios";
                                vaValues[2] = new psPortfoliosValueListRef.psPortfoliosValueListValueInfo();               
                                vaValues[2].ID=3;
                                vaValues[2].Text=@"Gizmos";
                                vaValues[3] = new psPortfoliosValueListRef.psPortfoliosValueListValueInfo();               
                                vaValues[3].Text=@"Wizards";
                                vaValues[3].Weight=3.14F;     

								// 'WeightDouble' property should be used to pass a double value(accepts precision up to 10 digits)
								// 'WeightDouble' accepts only non-zero values.
								// If both WeightDouble and Weight is passed to the object, then WeightDouble value will be saved in the database if the value provided is non-zero value else Weight value will be saved in the database.
								
								vaValues[4] = new psPortfoliosValueListRef.psPortfoliosValueListValueInfo();               
                                vaValues[4].Text=@"SubItems";
                                vaValues[4].WeightDouble=23.1023456789;     

								// 'Weight' property should be used if the value should be set to '0' as 'WeightDouble' accepts only non-zero values
								vaValues[5] = new psPortfoliosValueListRef.psPortfoliosValueListValueInfo();               
                                vaValues[5].Text=@"Categories";
                                vaValues[5].Weight=0;     								
                                #endregion Prepare vaValues

                                ValueListObj.UpdateValues(
                                        @"Domains", // sName             
                                        vaValues                 
                                        );
                         
                                MessageBox.Show("Success !", @"Set the 'Domains' value list to show only Items(1; 1.7), Portfolios, Gizmos(3;) , Wizards (; 3.14) , SubItems(;23.1023456789) and categories(;0).  Gizmos(3) will replace Applications(3)");
                        }
                        catch (System.Web.Services.Protocols.SoapException E)
                        {
                                MessageBox.Show("Error: " + 
                                                E.Detail.InnerText +  // This is the integer code of the error
                                                " " + E.Message, 
                                                @"Set the 'Domains' value list to show only Items(1; 1.7), Portfolios, Gizmos(3;) , Wizards (; 3.14) , SubItems(;23.1023456789) and categories(;0).  Gizmos(3) will replace Applications(3)");
                                                // in a real system, the Message is only displayed to support personnel, 
                                                // not to the user
                        }
                        catch (System.Exception E) 
                        {
                                MessageBox.Show("Unexcpected Error: \n" + 
                                                E.ToString(),
                                                @"Set the 'Domains' value list to show only Items(1; 1.7), Portfolios, Gizmos(3;) , Wizards (; 3.14) , SubItems(;23.1023456789) and categories(;0).  Gizmos(3) will replace Applications(3)");
                        }
                }                 
        }
}

    

